package com.api.acceptance.department;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Collection;

import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.VoidContextLoader;
import com.api.util.repo.impl.DomainUser;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.GroupApi;

@ContextConfiguration(loader = VoidContextLoader.class)
public class UploadAcceptance extends AbstractApiTest {

	private String idgroup;

	@BeforeClass
	protected void setUp() throws Exception {

		DomainUser mainAdmin = getRepo().getMainUser("uploadsDomain");
		getApi().login(mainAdmin.getAppId(), mainAdmin.getPassword());

		Collection<GroupApi> groups = getApi().getService(IGroupApiService.class).getGroups(0, 0, null, null, null, null, null)
				.getElements();
		GroupApi group = groups.iterator().next();
		this.idgroup = group.getUrn();
	}

	@Test
	public void testGetAllGroups() throws ZyncroApiException, FileNotFoundException {

		String oauthtoken = getApi().getAccessKey();
		String parentDocumentUrn = null;
		String iddocument = null;
		String description = "Description";

		File file = new File("pom.xml");
		Long length = file.length();
		String fileName = file.getName();
		InputStream inputStream = new FileInputStream(file);

		getApi().getService(IGroupApiService.class).upload(idgroup, oauthtoken, parentDocumentUrn, iddocument, description, fileName,
				length, inputStream);
	}
}
